
document.querySelector('#btn-register').addEventListener('click', async () => {
  const form = document.querySelector('.register-form')
  const data = serialize(form, { hash: true, empty: true })
  const { username, password } = data
  if (username.length < 5) {
    return showToast('请输入长度不小于5的用户名')
  }
  if (password.length < 5) {
    return showToast('请输入长度不小于5的密码')
  }
  try {
    const res = await axios({
      url: '/register',
      method: 'post',
      data: {
        username,
        password
      }
    })
    showToast(res.data.message)
    setTimeout(() => {
      location.href = './login.html'
    }, 1000)
  } catch (err) {
    console.log()
  }
})


